<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@page import="org.jeecgframework.web.util.StaticValue" %>
<%@include file="/context/mytags.jsp" %>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>
<html>
<head>
    <title>工程师服务单详情</title>
    <style type="text/css">
        .noSelect {
            border: 0;
            min-height: 1.146667rem;
            line-height: 1.146667rem;
            white-space: nowrap;
            overflow: hidden;
            padding-right: .6rem;
            background-color: #eee;
            background: transparent;
            appearance: none;
            -moz-appearance: none; /* Firefox */
            -webkit-appearance: none; /* Safari 和 Chrome */
        }
    </style>
    <script type="text/javascript" src="plug-in/jquery/jquerysession.js"></script>
</head>
<script>
</script>
<body>
<div style="margin-bottom:10px;">
    <img style="margin-bottom:-7px" src="plug-in/login/images/dispatch bill.png">
    <span class="list-title">${cbsService.code}</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <span style="font-size:13px;">服务进度：<span class="color-red">
        ${cbsService.speed}
    </span></span>
    <div style="position: absolute; text-align: center; width: 100%; margin-top:-20px;">
        <c:set value="<%=StaticValue.gcsssz%>" var="gcsssz"/>
        <c:set value="<%=StaticValue.fwywc%>" var="fwywc"/>
        <c:if test="${cbsService.speedstatus ne fwywc}">
            <a href="#" class="easyui-linkbutton l-btn" onclick="goSparepartApply('${cbsService.id}')">备件申请</a>
            <a href="#" class="easyui-linkbutton l-btn" onclick="writeCompletionReport()">填写完工报告</a>
        </c:if>
        <a href="#" class="easyui-linkbutton l-btn" onclick="checkCompletionReport()">查看完工报告</a>
        <c:if test="${cbsService.speedstatus ne gcsssz && cbsService.speedstatus ne fwywc}">
            <a href="#" class="easyui-linkbutton l-btn" onclick="findArgEngineer('${cbsService.id}')">派单工程师</a>
        </c:if>
    </div>
</div>

<div class="subtitle">
    <p>服务描述</p>
    <input type="hidden" value="${cbsService.id}" name="cbsId" id="cbsId">
    <table class="nobordertable noborder">
        <tbody>
        <tr>
            <td class="al_r" width="20%">
                <label>服务类型:</label>
            </td>
            <td width="30%">
                ${cbsService.t1Name}》${cbsService.t2Name}
            </td>
            <td class="al_r" width="20%">
                <label>故障照片:</label>
            </td>
            <td width="30%">
                <c:if test="${not empty zyFileLogEntityA}">
                    <c:forEach items="${zyFileLogEntityA}" var="a">
                        <div href="#" onclick="downloadFile('${a.id}')">
                            <input type="hidden" id="fileIdas" value='${a.id}'>
                            <span style="color:blue;" id='${a.id}'>
                                <a class="color-blue"
                                   href="fileUploadController.do?downLoadFile&fileLogId=${a.id}">${a.oldFileName }</a></span>
                        </div>
                    </c:forEach>
                </c:if>
            </td>
        </tr>
        <tr>
            <td class="al_r" width="20%">
                <label>巴可派单时间:</label>
            </td>
            <td width="30%">
                ${cbsService.assignTime}
            </td>
            <td class="al_r" width="20%">
                <label>级别:</label>
            </td>
            <td width="30%">
                ${cbsService.level}
            </td>
        </tr>
        <tr>
            <td class="al_r" width="20%">
                <label>客户需求描述:</label>
            </td>
            <td width="30%">
                ${cbsService.description}
            </td>
            <td class="al_r" width="20%">
                <label>处理时长:</label>
            </td>
            <td width="30%">
                ${cbsService.dealWithTiem}
            </td>
        </tr>
        <tr>

            <td class="al_r" width="20%">
                <label>派单要求:</label>
            </td>
            <td width="30%">
                ${cbsService.assign_des}
            </td>
            <td class="al_r" width="20%">
                <label>巴可HD处理过程:</label>
            </td>
            <td width="30%">
                ${cbsService.handleDes}
            </td>
        </tr>
        </tbody>
    </table>
    <div style="width: 98%; margin: 10px auto;">附加任务</div>
    <table class="ftable">
        <tbody>
        <tr>
            <th>对象</th>
            <th>待办内容</th>
        </tr>
        <c:forEach items="${cbsServiceTaskMap}" var="task">
            <tr>
                <td>${task.attachTaskId.objectName}</td>
                <td>${task.attachTaskId.content}</td>
            </tr>
        </c:forEach>

        </tbody>
    </table>
</div>
<div class="subtitle">
    <p>客户信息</p>
    <table class="nobordertable noborder" style="border: none;">
        <tbody>
        <tr>
            <td class="al_r" width="20%">
                <label>联系人电话:</label>
            </td>
            <td width="30%">
                ${cbsService.phone}
            </td>
            <td class="al_r" width="20%">
                <label>联系人邮箱:</label>
            </td>
            <td width="30%">
                ${cbsService.email}
            </td>
        </tr>
        <tr>
            <td class="al_r" width="20%">
                <label>联系人姓名:</label>
            </td>
            <td width="30%">
                ${cbsService.name}
            </td>
            <td class="al_r" width="20%">

            </td>
            <td width="30%">

            </td>
        </tr>
        <tr>
            <td class="al_r" width="20%">
                <label>影院名称:</label>
            </td>
            <td width="30%">
                ${cbsService.ciName}
            </td>
            <td class="al_r" width="20%">
                <label>院线:</label>
            </td>
            <td width="30%">
                ${cbsService.type_intheater_name}
            </td>
        </tr>
        <tr>
            <td class="al_r" width="20%">
                <label>影院地址:</label>
            </td>
            <td width="30%">
                ${cbsService.address}
            </td>
            <td class="al_r" width="20%">

            </td>
            <td width="30%">

            </td>
        </tr>
        </tbody>
    </table>
</div>
<div class="subtitle">
    <p>设备信息</p>
    <table class="nobordertable noborder" style="border: none;">
        <tbody>
        <tr>
            <td class="al_r" width="20%">
                <label>设备序列号:</label>
            </td>
            <td width="30%">
                ${cbsService.sn}
            </td>
            <td class="al_r" width="20%">
                <label>设备型号:</label>
            </td>
            <td width="30%">
                ${cbsService.type_desc}
            </td>
        </tr>
        <tr>
            <td class="al_r" width="20%">
                <label>保修期状态:</label>
            </td>
            <td width="30%">
                ${cbsService.inReparirDateVal}
            </td>
            <td class="al_r" width="20%">
                <label>激光改造:</label>
            </td>
            <td width="30%">
                ${cbsService.laser}
            </td>
        </tr>
        </tbody>
    </table>
</div>
<div class="subtitle">
    <p>备件申请</p>
    <c:forEach items="${cbsEquipmentApplyDetailList}" var="a" varStatus="m">
        <div style="width: 98%; margin: 0 auto; padding:5px 0px;">
            <span style="font-size:16px; font-weight: bold;">备件申请${m.index+1}</span>
        </div>
        <table class="ftable">
            <tr>
                <th>备件申请单号</th>
                <th>备件类型</th>
                <th>备件号</th>
                <th>备件数量</th>
                <th>申请理由</th>
                <th>审批状态</th>
                <th>工程师注意事项</th>
            </tr>
            <tr>
                <td>${a.applyId.recordId}</td>
                <td>${a.typeDes}</td>
                <td>${a.item}</td>
                <td>${a.total}</td>
                <td>${a.applyId.applyReason}</td>
                <td>
                    <c:if test="${a.applyId.status==1}">待审批</c:if>
                    <c:if test="${a.applyId.status==2}">审批已通过</c:if>
                    <c:if test="${a.applyId.status==3}">审批未通过</c:if>
                </td>
                <td>${a.applyId.engineerAttention}</td>
            </tr>
            <tr>
                <td colspan="7">
                    <table class="ftable1">
                        <tr>
                            <th>发货状态</th>
                            <th>预计到货时间</th>
                            <th>实际到货时间</th>
                            <th>发货单号</th>
                            <th>备件类型</th>
                            <th>备件号</th>
                            <th>物流</th>
                            <th>物流发货时间</th>
                        </tr>
                        <c:forEach items="${a.cbsDeliverEquipmentEntityList}" var="b">
                            <tr>
                                <td><t:dictSelect clazz="noSelect" readonly="readonly" field="status"
                                                  typeGroupCode="<%=StaticValue.Deliver_State %>"
                                                  defaultVal="${b.deliverId.status}"/></td>
                                <td>${fn:substring(b.deliverId.expectTime,0,19)}</td>
                                <td>${fn:substring(b.deliverId.getTime,0,19)}</td>
                                    <%--签收时间--%>
                                <td>${b.deliverId.code}</td>
                                <td>${a.typeDes}</td>
                                <td>${a.item}</td>
                                <td>${b.deliverId.deliverLogistics}</td>
                                <td>${fn:substring(b.deliverId.logisticsSendTime,0,19)}</td>
                            </tr>
                        </c:forEach>
                    </table>
                </td>
            </tr>
        </table>
        <c:if test="${a.applyId.status==1}">
            <div style="margin:10px auto;text-align: center;">
                <c:if test="${a.applyId.judge!=2}">
                    <a class="easyui-linkbutton l-btn"
                       onclick="sureSpare(${a.applyId.status},'${a.applyId.id}')">确认备件</a>
                </c:if>
                <a class="easyui-linkbutton l-btn" onclick="updateSpare(${a.applyId.status},'${a.applyId.id}')">修改备件</a>
            </div>
        </c:if>
    </c:forEach>
</div>
<div class="subtitle">
    <p>服务时间</p>
    <table class="nobordertable noborder" style="border: none;">
        <tbody>
        <tr>
            <td class="al_r" width="20%">
                <label>预约上门时间:</label>
            </td>
            <td width="30%">
                <c:if test="${not empty cbsService.orderTimeAgin}">
                    ${fn:substring(cbsService.orderTimeAgin,0,19)}
                </c:if>
                <c:if test="${empty cbsService.orderTimeAgin}">
                    ${fn:substring(cbsService.ordertime,0,19)}
                </c:if>
            </td>
            <td class="al_r" width="20%">
                <label>备注:</label>
            </td>
            <td width="30%">
                ${cbsService.remarks}
            </td>
        </tr>
        </tbody>
    </table>
</div>
<div class="subtitle">
    <p>服务日志</p>
    <table class="ftable">
        <tbody>
        <tr>
            <th>操作人</th>
            <th>时间</th>
            <th>描述</th>
        </tr>
        <c:forEach items="${cbsServiceLogList}" var="log" varStatus="stat">
            <c:if test="${!stat.last}">
                <tr>
                    <td>${log.createName}</td>
                    <td>${log.createDate}</td>
                    <td>${log.description}</td>
                </tr>
            </c:if>
        </c:forEach>
        </tbody>
    </table>
</div>
</body>

<script>

    //填写完工报告
    function writeCompletionReport() {
        if (judge()) {
            var flag = false;
            var speedStatus = '${cbsService.speed}';
            var cbsId = '${cbsService.id }';
            //      只有第三方服务进度为“工程师已接受”或“工程师实施中”的服务单才可以提交完工
            if (speedStatus == '工程师已接受' || speedStatus == '工程师实施中') {
                //现场检测类型，至少有一次上门签到记录
                $.ajax({
                    url: "cbsServiceAssignListController.do?doorToDoorCheckIn",
                    data: {
                        "id": cbsId
                    },
                    cache: false,
                    dataType: 'json',
                    async: false,
                    type: 'POST',
                    success: function (data) {
                        if (data.success) {
                            //判断服务类型，根据服务类型不同，跳转不同的完工单页面
                            var type = data.attributes['type'];
                            // alert("服务单类" + type);
                            console.info("服务单类" + type);
                            if (type == 'type-yqfx') {  //
                                flag = true;
                                addOneTab('引擎翻新现场检测完工单', 'cbsServiceReportController.do?goEngineRefurbished&id=' + cbsId);
                            }
                            if (type == 'type-yqfxys') {  //
                                flag = true;
                                addOneTab('引擎翻新验收单', 'cbsServiceReportController.do?goEngineRefurbishedSign&id=' + cbsId);
                            }
                            if (type == 'type-ggfx') {
                                flag = true;
                                addOneTab('光管翻新验收单', 'cbsServiceReportController.do?goLighttubeAcceptance&id=' + cbsId);
                            }
                            if (type == 'type-jszc') {
                                flag = true;
                                addOneTab('技术支持完工单', 'cbsServiceReportController.do?goTechnologyAgree&id=' + cbsId);
                            }
                            if (type == 'type-yj') {
                                flag = true;
                                openwindow('', 'cbsServiceReportController.do?choose&cbsId=' + cbsId, '', 500, 300);
                                //addOneTab('现场检测完工单', 'cbsServiceReportController.do?goReferDetection&id=' + cbsId);
                            }
                            if (type == 'type-wx') {
                                flag = true;
                                $.ajax({
                                    url: "cbsServiceReportController.do?goTemporaryPage",
                                    data: {
                                        "id": cbsId
                                    },
                                    cache: false,
                                    dataType: 'json',
                                    async: false,
                                    type: 'POST',
                                    success: function (data) {
                                        var attributes = data.attributes;
                                        if (attributes.reportCategory == 1) {
                                            addOneTab('现场服务完工报告', 'cbsServiceReportController.do?cbsServiceReportXC&id=' + cbsId);
                                        }
                                        if (attributes.reportCategory == 2) {
                                            addOneTab('远程服务完工报告', 'cbsServiceReportController.do?RemoteService&id=' + cbsId);
                                        }
                                        if (attributes.reportCategory == -1) {
                                            openwindow('是否现场服务', 'cbsServiceReportController.do?fieldservice&id=' + cbsId, '', 350, 200);
                                        }
                                    }
                                })

                            }
                            if (type == 'type-xcjc') {
                                flag = true;
                                addOneTab('现场检测完工单', 'cbsServiceReportController.do?goReferDetection&id=' + cbsId);
                            }

                            if (flag == false) {
                                parent.window.tip("此服务单请邮件联系中影巴可HD提交完工资料");

                            }

                        } else {
                            tip(data.msg);
                        }
                    }
                });
            } else if (speedStatus == "服务已完成") {
                tip("服务已完成，不能填写完工单");
            } else {
                tip("只有工程师已接受或者工程师实施中才能填写完工单！");
            }

        } else {
            tip("操作人与派单人不符，请刷新系统！");
        }
    }

    //查看完工报告
    function checkCompletionReport() {
        var speedStatus = '${cbsService.speed}';
        var cbsId = '${cbsService.id }';
//      只有第三方服务进度为“工程师已接受”或“工程师实施中”的服务单才可以提交完工
        //至少有一次上门签到记录
        $.ajax({
            url: "cbsServiceAssignListController.do?doorToDoorCheckIn",
            data: {
                "id": cbsId
            },
            cache: false,
            dataType: 'json',
            async: false,
            type: 'POST',
            success: function (data) {
                if (data.success) {
                    //判断服务类型，根据服务类型不同，跳转不同的完工单页面
                    var type = data.attributes['type'];
                    // alert("服务单类" + type);
                    console.info("服务单类" + type);
                    if (type == 'type-yqfx') {  //
                        addOneTab('引擎翻新现场检测完工单', 'cbsServiceReportController.do?goEngineRefurbished&id=' + cbsId);
                    }
                    if (type == 'type-yqfxys') {  //
                        addOneTab('引擎翻新验收单详情', 'cbsServiceReportController.do?goEngineRefurbishedSignDetail&id=' + cbsId);
                    }
                    if (type == 'type-ggfx') {
                        addOneTab('光管翻新验收单', 'cbsServiceReportController.do?goLighttubeAcceptanceDetail&id=' + cbsId);
                    }
                    if (type == 'type-jszc') {
                        addOneTab('技术支持完工单', 'cbsServiceReportController.do?goTechnologyAgreeDetail&id=' + cbsId);
                    }
                    if (type == 'type-wx') {
                        $.ajax({
                            url: "cbsServiceReportController.do?goTemporaryPageOnSubmit",
                            data: {
                                "id": cbsId
                            },
                            cache: false,
                            dataType: 'json',
                            async: false,
                            type: 'POST',
                            success: function (data) {
                                var attributes = data.attributes;

                                if (attributes.reportCategory == -1) {
                                    tip("请先填写完工单");
                                    return false;
                                } else {
                                    addOneTab('完工报告', 'cbsServiceReportController.do?lookFinishReport&id=' + cbsId);
                                }
                            }
                        })

                    }
                    if (type == 'type-yj') {
                        $.ajax({
                            url: "cbsDelinerController.do?jumpPage",
                            data: {"id": cbsId},
                            async: false,
                            cache: false,
                            dataType: 'json',
                            type: 'POST',
                            success: function (data) {
                                if ("type-yj" == data.msg) {
                                    addOneTab('现场检测完工单详情', 'cbsServiceReportController.do?goReferDetectionDetail&id=' + cbsId);
                                }
                                if ("type-yqfx" == data.msg) {
                                    addOneTab('引擎翻新现场检测完工单详情', 'cbsServiceReportController.do?goEngineRefurbishedDetail&id=' + cbsId);
                                }
                                if ("请先填写相应完工单" == data.msg) {
                                    tip(data.msg);
                                }
                            }
                        });
                        //addOneTab('现场检测完工单详情', 'cbsServiceReportController.do?goReferDetectionDetail&id=' + cbsId);
                    }

                } else {
                    tip(data.msg);
                }
            }
        });

    }

    //工程师查询条件
    function findArgEngineer(planIds) {

        if (judge()) {
            createwindow("分派", "cbsServiceAssignListController.do?findPeopleList&planIds=" + planIds, 600, 400);
        } else {
            tip("操作人与派单人不符，请刷新系统！");
        }
    }

    /*故障照片下载*/
    function downloadFile(fileId) {
        if (judge()) {
            myDownload("fileUploadController.do?downLoadFile&fileLogId=" + fileId + "");
        } else {
            tip("操作人与派单人不符，请刷新系统！");
        }
    }

    //确认备件 status==1 待审批状态
    function sureSpare(status, id) {
        if (judge()) {
            var speedStatus = '${cbsService.speedstatus}';
            if (status == 1) {
                if (speedStatus == '5' || speedStatus == '6' || speedStatus == '7') {
                    $.dialog({
                        content: "url:cbsEquipmentApplyController.do?goPass&sign=1&id=" + id,
                        zIndex: 100,
                        title: '通过',
                        lock: true,
                        width: '500px',
                        height: '300px',
                        left: '50%',
                        top: '50%',
                        opacity: 0.4,
                        init: function () {
                            top.myWindow = window;
                        },
                        button: [{
                            name: '确认',
                            callback: function () {
                                var iframe = this.iframe.contentWindow;
                                var csaAttention = $(iframe.document).find("#csaAttention").val();
                                var engineerAttention = $(iframe.document).find("#engineerAttention").val();
                                $.ajax({
                                    url: "cbsEquipmentApplyController.do?pass",
                                    data: {
                                        "id": id,
                                        "csaAttention": csaAttention,
                                        "engineerAttention": engineerAttention
                                    },
                                    async: false,
                                    cache: false,
                                    dataType: 'json',
                                    type: 'POST',
                                    error: function () {// 请求失败处理函数
                                    },
                                    success: function (data) {
                                        if (data.success) {
                                            closetab("服务订单详情");
                                        }
                                    }
                                });
                            },
                            focus: true
                        }, {
                            name: '取消',
                            callback: function () {
                            }
                        }]
                    });
                } else {
                    tip("只有工程师接受后才能修改备件！");
                }
            } else {
                tip("备件已审批，不能修改备件！");
            }
        } else {
            tip("操作人与派单人不符，请刷新系统！");
        }
    }

    /*修改备件*/
    function updateSpare(status, id) {
        if (judge()) {
            var speedStatus = '${cbsService.speedstatus}';
            if (status == 1) {   //待审批状态
                if (speedStatus == '5' || speedStatus == '6' || speedStatus == '7') {
                    addOneTab('修改备件', 'cbsServiceAssignListController.do?goSparepartApply&id=' + id + "&sign=1", '');
                } else {
                    tip("只有工程师接受后才能修改备件！");
                }
            } else {
                tip("备件已经审批完成，不能修改备件！");
            }
        } else {
            tip("操作人与派单人不符，请刷新系统！");
        }
    }

    /**
     * 备件申请
     * @param id
     */
    function goSparepartApply(id) {
        if (judge()) {
            openwindow('备件申请', 'cbsServiceController.do?goSparepartApply&id=' + id, '', 800, 500);
        } else {
            tip("操作人与派单人不符，请刷新系统！");
        }
    }


    /*判断派单人是否是当前登录人*/
    function judge() {
        var cbsId = $("#cbsId").val();
        var flag = false;
        $.ajax({
            url: "cbsServiceController.do?judgePeople",
            data: {
                "cbsId": cbsId,
                "type": "3"
            },
            async: false,
            cache: false,
            dataType: 'json',
            type: 'POST',
            error: function () {// 请求失败处理函数
            },
            success: function (data) {
                if (data.success) {
                    flag = true;
                }
            }
        });

        return flag;
    }

</script>
</html>
